#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple Linux kernel module to print floating point numbers using fixed-point arithmetic");
MODULE_VERSION("0.1");

// Function to convert a fixed-point number to string
static void fixed_point_to_string(char *buffer, size_t buffer_size, int value, int frac_bits) {
    int int_part = value >> frac_bits;
    int frac_part = value & ((1 << frac_bits) - 1);
    int frac_as_int = (frac_part * 10000) >> frac_bits; // 4 decimal places
    snprintf(buffer, buffer_size, "%d.%04d", int_part, frac_as_int);
}

static int __init my_module_init(void) {
    char buffer[20];

    // Fixed-point arithmetic parameters
    int frac_bits = 16;
    float pi = 333.14159;
    int fixed_pi = (int)(pi * (1 << frac_bits));
    printk("fixed_pi: %d\n", fixed_pi);

    fixed_point_to_string(buffer, sizeof(buffer), fixed_pi, frac_bits);
    printk(KERN_INFO "Float value: %s\n", buffer);

    return 0;
}

static void __exit my_module_exit(void) {
    printk(KERN_INFO "Float printer module unloaded\n");
}

module_init(my_module_init);
module_exit(my_module_exit);

